/*
 *  rvCollision.h
 *  ReVerb
 *
 *  Created by Brandon Braley on 8/21/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef		__ICOLLISION_H__
#define		__ICOLLISION_H__

#include "rvMath.h"

namespace ReVerb
{
	/**
	 *	A pure virtual abstract interface that outlines collision functionality
	 *	that is to be implemented by child classes
	 */
	class ICollision
	{
	public:
		/**
		 *	Constructors
		 */
							ICollision()							{}
							ICollision( const ICollision& ref )		{}

		/**
		 *	Destructor
		 */
		virtual			~ICollision()								= 0;

		/**
		 *	Assigment operators
		 */
		virtual ICollision&	operator=( const ICollision& ref )		
		{
			return *this;
		}

		/**
		 *	Checks if the given point falls inside of the
		 *	collidable object
		 *
		 *	@int param	Point
		 *		A 2D point on the same plane as this ICollision object
		 *
		 *	@return
		 *		True if the point falls inside of this ICollision's
		 *		collision bounds
		 */
		virtual bool		HasCollided( const Vec2D& Point )			const
		{
			return false;
		}

		/**
		 *	Checks if the given ICollision object's collision bounds
		 *	overlap this ICollision object's collision bounds
		 *
		 *	@in param	Object
		 *		The object to test a collision with
		 *
		 *	@out param	Info
		 *		The overlapping collision data
		 *		(only valid if a collision occurs and true is returned)
		 *
		 *	@return
		 *		True if the object is colliding with this ICollision
		 *		object
		 */
		virtual bool		HasCollided( const ICollision& Object,
										 ICollision& Info )				const
		{
			return false;
		}
	};
	ICollision::~ICollision() {}

	/**
	 *	Implements rectangle collision for the ICollision interface
	 */
	class CollisionRect	:	public ICollision
	{
	public:
		/**
		 *	Constructors
		 */
							CollisionRect()
		{
		}
							CollisionRect( const CollisionRect& ref )	:
			m_Min(ref.m_Min),
			m_Max(ref.m_Max)
		{
		}

							CollisionRect( const Vec2D& Min, const Vec2D& Max  )	:
			m_Min(Min),
			m_Max(Max)
		{
		}

							CollisionRect( const float Min_X, const float Min_Y,
										   const float Max_X, const float Max_Y )	:
			m_Min( Vec2D(Min_X, Min_Y) ),
			m_Max( Vec2D(Max_X, Max_Y) )
		{
		}

		/**
		 *	Destructor
		 */
		virtual				~CollisionRect()				{}

		/**
		 *	Assigment operators
		 */
		virtual CollisionRect&	operator=( const CollisionRect& ref )
		{
			m_Min = ref.m_Min;
			m_Max = ref.m_Max;
			return *this;
		}

		/**
		 *	Checks if the given point falls inside of this object's
		 *	collision rectangle
		 *
		 *	@in param	Point
		 *		A 2D point on the same plane as this CollisionRect object
		 *
		 *	@return
		 *		True if the point falls inside of this CollisionRect's
		 *		collision rectangle
		 */
		virtual bool		HasCollided( const Vec2D& Point )			const
		{
			if ( Point.x < m_Min.x || Point.x > m_Max.x )
				return false;
			if ( Point.y < m_Min.y || Point.y > m_Max.y )
				return false;

			return true;
		}

		/**
		 *	Checks if the given CollisionRect object's collision rect
		 *	overlaps this CollisionRect object's collision rect
		 *
		 *	@in param	Object
		 *		The object to test a collision with
		 *
		 *	@out param	Info
		 *		The rectangle where the two objects overlap in screen space
		 *		(only valid if collision occurs and true is returned)
		 *
		 *	@return
		 *		True if the object's collision rect overlaps this CollisionRect
		 *		object's collision rect
		 */
		virtual bool		HasCollided( const CollisionRect& Object,
										 CollisionRect& Info )			const
		{
			bool bHasCollided = false;

			/*if ( Object.m_Max.x > m_Min.x && Object.m_Min.x < m_Max.x )
			{
				if ( Object.m_Max.x > m_Min.x )
					Info.m_Min.x = m_Min.x + (Object.m_Max.x - m_Min.x);
				else
					Info.m_Min.x = Object.m_Min.x + (Object.m_Max.x - m_Min.x);
				bHasCollided = true;
			}
			if ( Object.m_Max.y > m_Min.y || Object.m_Min.y < m_Max.y )
			{
				bHasCollided = true;
			}*/

			return bHasCollided;
		}

	protected:
		/**
		 *	A 2 dimensional point on a plane that represents the smallest
		 *	point of the collision rectangle and the largest point of the
		 *	collision rectangle
		 */
		Vec2D				m_Min, m_Max;
	};
}

#endif		//__ICOLLISION_H__